package com.hsmw.api.service;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.hsmw.api.mapper.HsmwPaymentRecordMapper;
import com.hsmw.api.mapper.HsmwRechargeRecordMapper;
import com.hsmw.common.base.BaseService;
import com.hsmw.domain.HsmwPaymentRecord;
import com.hsmw.domain.HsmwRechargeRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional(isolation = Isolation.REPEATABLE_READ, propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
public class HsmwPaymentRecordService  extends BaseService<HsmwPaymentRecordMapper, HsmwPaymentRecord> {


    @Autowired
    private HsmwPaymentRecordMapper hsmwPaymentRecordMapper;

    public IPage<HsmwPaymentRecord> selectpageList(IPage page, HsmwPaymentRecord hsmwRechargeRecord) {
        LambdaQueryWrapper<HsmwPaymentRecord> lambdaQuery = Wrappers.lambdaQuery(HsmwPaymentRecord.class);
        if (StrUtil.isNotBlank(hsmwRechargeRecord.getType())) {
            lambdaQuery.eq(HsmwPaymentRecord::getType, hsmwRechargeRecord.getType());
        }
        if (StrUtil.isNotBlank(hsmwRechargeRecord.getStatus())) {
            lambdaQuery.eq(HsmwPaymentRecord::getStatus, hsmwRechargeRecord.getStatus());
        }
        if (StrUtil.isNotBlank(hsmwRechargeRecord.getCompanyId())) {
            lambdaQuery.eq(HsmwPaymentRecord::getCompanyId, hsmwRechargeRecord.getCompanyId());
        }
        lambdaQuery.orderByDesc(HsmwPaymentRecord::getCreateTime);
        IPage<HsmwPaymentRecord> orderIPage = hsmwPaymentRecordMapper.selectPage(page, lambdaQuery);
        return orderIPage;
    }
}
